#!/bin/bash
Downurl='https://gitee.com/RuoliCloud/YUMsh/raw/master'
uptime=$(curl -sSL https://gitee.com/RuoliCloud/YUMsh/raw/master/yumupdate.txt)
function Chsystem() {
  echo "Please input system version number"
  echo "Example Centos8 : you should input 8"
  echo "Centos9 : you should input 9"
  echo "Now bash only run on 8/9"
  read -p "Input: " system
}
function Fast() {
  #快捷启动
  rm -rf "$0"
  wget "$Downurl"/yum.sh -O /bin/yumsh
  chmod -R 777 /bin/yumsh
}
function Pre() {
  #备份原YUM
  mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  #备份原Epel源
  mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
  #删除多余Repo源
  rm -rf /etc/yum.repos.d/*.repo
  clear
}
function Finish() {
  echo "None"
  yum clean all
  yum makecache
  Fast
  clear
  echo "Finish"
  echo "If you want to run again"
  echo "You can enter:yumsh"
  exit
}
function AnolisOS() {
  cd /etc/yum.repos.d/ || return
  wget -O repos.zip https://gitee.com/RuoliCloud/YUMsh/raw/master/repos.zip
  unzip repos.zip
  cd /root || return
  Finish
}

function Aliyunchange() {
  case "${system}" in
  6)
    wget -O /etc/yum.repos.d/Centos-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
    ;;
  7)
    wget -O /etc/yum.repos.d/Centos-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    ;;
  8)
    wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-archive-8.repo
    ;;
  *)
    echo "None for Aliyun"
    ;;
  esac
  Finish
}
function Wangyichange() {
  case "${system}" in
  6)
    wget -O /etc/yum.repos.d/Centos-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
    ;;
  7)
    wget -O /etc/yum.repos.d/Centos-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
    ;;
  *)
    echo "None for Wangyi "
    ;;
  esac
  Finish
}
function Returnchange() {
  rm -rf /etc/yum.repos.d/CentOS-Base.repo
  mv /etc/yumrepos.d/CentOS-Base.repo.bak /etc/yum.repos.d/CentOS-Base.repo
  Finish
}
Fast
clear
echo "Shell updated on ${uptime}"
echo "Written by Ruoli"
echo "1 --- Aliyun YUM && Epel"
echo "2 --- Wangyi-163 YUM"
echo "3 --- Return YUM"
echo "4 --- Download AnolisOS YUM"
echo "* --- Exit YUMsh"
echo "Notice: NO.4 only for AnolisOS to repair YUM repos"
read -p "Please choose:" yfrom
case $yfrom in
1)
  Pre
  Chsystem
  Aliyunchange
  ;;
2)
  Pre
  Chsystem
  Wangyichange
  ;;
3)
  Returnchange
  ;;
4)
  AnolisOS
  ;;
*)
  Fast
  clear
  echo "None"
  echo "If you want to run again"
  echo "You can enter:yumsh"
  exit
  ;;
esac
